#define _CRT_SECURE_NO_WARNINGS 1

//https://leetcode.cn/problems/combinations/

class Solution {
    vector<vector<int>> ret;
    vector<int> path;
    int len;
public:
    vector<vector<int>> combine(int n, int k) {
        len = n;
        dfs(1, k);
        return ret;
    }

    void dfs(int pos, int k)
    {
        if (path.size() == k)
        {
            ret.push_back(path);
            return;
        }

        for (int i = pos; i <= len; i++)
        {
            path.push_back(i);
            dfs(i + 1, k);
            path.pop_back();
        }
    }
};